#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : gtmsAutoTestProject 
@File    : idle_table_server.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/6/15 14:57 
@Describe: POS空闲台位数量接口业务实现
"""
from APIs.posApi.table.table_api import TableApi
from Comm.tools.toolsControl import ToolsHandler
from Comm.logUtils.logControl import LogHandler

logger = LogHandler().get_logger()


class IdleTableServer:
    """POS空闲台位"""

    def __init__(self, brandCode, environment):
        """
        构造函数
        :param brandCode: 品牌编码
        :param environment: 环境
        """
        self.table_api = TableApi(brandCode, environment)

    def get_idle_table(self) -> dict:
        table_list = self.table_api.table_list()
        if type(table_list) is not dict:  # 判断支付方式接口请求是否成功
            idle_table_list = ToolsHandler.get_json_result(table_list, '$.data')
            idle_table_total = 0
            for i in idle_table_list:
                table_status = i['status']
                if table_status == 0:
                    idle_table_total += 1
            result_info = {"code": "200", "message": "请求成功", "data": idle_table_total}
            return result_info
        elif type(table_list) is dict:
            logger.error("请求POS台位列表接口报错!错误原因:{}".format(table_list))
            return table_list
